using System;
using UnityEngine;

namespace InventorySystem
{
    [Serializable]
    public class InventorySlot
    {
        public event EventHandler<InventorySlotStateChengedArgs> StateChanged;

        [SerializeField]
        private ItemStack _state;

        private bool _active;



        public ItemStack State 
        {
            get => _state;
            set 
            {
                _state = value;
                NotifyAbuoutStateChange();
            }
        }

        public bool Active 
        {
            get => _active;
            set 
            {
                _active = value;
                NotifyAbuoutStateChange();
            }
        }

        public bool HasItem => _state?.Item != null;
        public ItemDifinition Item => _state?.Item;

        public int NuberOfItens 
        {
            get => _state.NumberOfItems;
            set 
            {
                _state.NumberOfItems = value;
                NotifyAbuoutStateChange();
            }
        }

        public void Clear() 
        {
            State = null;
        }

        private void NotifyAbuoutStateChange() 
        {
            StateChanged?.Invoke(this, new InventorySlotStateChengedArgs(_state,_active));
        }

        

      
    }
}